import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;


public class InvoiceDown {

	public static void main(String[] args) {

	String url, dest, ans;
	Scanner in = new Scanner(System.in);
	url = "";
	dest ="";
	
	if(checkNewInvoices()==true)
	{
		
		ans="";
		do
		{
			System.out.println("New Invoices have been found.");
			System.out.println("Do you want to download them? y/n:");
			ans = in.nextLine();
		}
		while(readYesNoAnswer(ans)==false);
	}
	
	
	
	
		
	}

	private static boolean readYesNoAnswer(String ans) 
	{
		if(ans.startsWith("y")||ans.startsWith("Y")||ans.startsWith("n")||ans.startsWith("N"))
		{
			return true;
		}
		return false;
		
	}

	private static boolean checkNewInvoices() 
	{
		System.out.println("New invoices found!");
		return true;
	}

	
	private static void downFile(String url, String dest) {
		int count;

		
        try {

         URL urlImg = new URL(url);
         URLConnection connection = urlImg.openConnection();
         connection.connect();

         int lenghtOfFile = connection.getContentLength();
         int currPercent = 0;
         InputStream input = new BufferedInputStream(urlImg.openStream(), 8192);


         
		OutputStream output = new FileOutputStream(dest);

         byte data[] = new byte[1024];

         long total = 0;

         while ((count = input.read(data)) != -1) {
             total += count;
             currPercent = (int) ((total*100)/lenghtOfFile);
             
             percent(currPercent);
             output.write(data, 0, count);
         }

         output.flush();           
         output.close();
         input.close();
         
        } catch (Exception e) {
            e.getMessage();
        }

	
	
	}

	
	public static void percent(int perc)
	{
		int lastSize = 2;
		if(perc>9 &&perc<100)
		{
			lastSize = 3;
		}
		if(perc>=100)
		{
			lastSize = 4;
		}
		
		  for (int j = 0; j < lastSize; j++) {
		    System.out.print("\b");
		  }

		  String is = Integer.toString(perc);
		  System.out.print(is+"%");
		  
		
	}

	
	public static void halt()
		{
			try {
		        System.in.read();
		    } catch (IOException e) {
		        e.printStackTrace();
		    }
		}
		

}
